package com.youkeda.test.http;

import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;

/**
 * @author xshuai
 */
public class GetPage {
    public static void main(String[] args) {
        String url = "https://docs.qq.com/sheet/DRk5nZVNFellRaFBZ?tab=BB08J2&c=E10A0AW0";
        GetPage getPage = new GetPage();
        String content = getPage.getContent(url);
        System.out.println("API调用结果");
        System.out.println(content);
    }

    public String getContent(String url) {
        String result = "";
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder().url(url
        ).build();
        Call call = okHttpClient.newCall(request);
        try {
            Response response = call.execute();
            int code = response.code();
            System.out.println("状态码：" + code);
            result = response.body().string();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }
}
